<?php
$str_random = random_string(7);

$_SESSION['str_random'] = $str_random;
if (sizeof($arr_single_citizen)>0){
	$v_username = $arr_single_citizen['C_USERNAME'];
	$v_xml_str = $arr_single_citizen['C_XML_DATA'];
}else{
	$v_username = "";
	$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
}
$v_display_none = "block";
$v_password_optional = false;
$v_username_readonly = "";
$v_register_button = _CONST_REGISTER_BUTTON;
$v_citizen_title = CONST_CITIZEN_REGISTER_TITLE;
if (sizeof($arr_single_citizen)>0){
	$v_display_none = "none";
	$v_password_optional = true;
	$v_username_readonly = "readonly";
	$v_register_button = _CONST_SAVE_BUTTON;
	$v_citizen_title = CONST_CITIZEN_INFOMATION_TITLE;
}
//cac file chua cau truc cua bang
$v_xml_file = "../../xml/citizen/dang_ky_su_dung_dich_vu_cong.xml";
$v_xml_string_in_file = _read_file($v_xml_file);
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_xml_string_in_file);
$table_struct_rax->record_delim = 'common_para';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_first_col_width = $table_struct_row["first_col_width"];
?>
<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
	<tr>
		<td class='large_title'><?php echo $v_citizen_title ?></td>
	</tr>
</table>		
<form action='index.php' method='post' name='f_dsp_single_citizen'>
	<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_CITIZEN'>
	<input type='hidden' name='hdn_question' value=''>
	<input type='hidden' name='hdn_list_xml_tag' value=''>
	<input type='hidden' name='hdn_list_xml_value' value=''>
<table width='100%' class='form_table1'  border='0' cellspacing='0' cellpadding='0'>
	<col width="<?php echo $v_first_col_width?>"><col width="<?php echo (100-$v_first_col_width)?>%">
	<tr>
		<td class="normal_label"><?php echo CONST_USERNAME_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_label"><input name="txt_username" type="text" value="<?php echo $v_username?>" class="normal_textbox" <?php echo $v_username_readonly?> style="width:80%" maxlength="<?php echo CONST_USERNAME_MAXLENGTH; ?>" message="<?php echo CONST_USERNAME_MESSAGE;?>" optional="<?php echo CONST_USERNAME_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr style="display:<?php echo $v_display_none?>">
		<td class="normal_label"><?php echo CONST_PASSWORD_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_label"><input name="txt_password" type="password" class="normal_textbox" style="width:80%" maxlength="<?php echo CONST_PASSWORD_MAXLENGTH; ?>" message="<?php echo CONST_PASSWORD_MESSAGE;?>" optional="<?php echo $v_password_optional;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr style="display:<?php echo $v_display_none?>">
		<td class="normal_label"><?php echo CONST_RE_PASSWORD_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_label"><input name="txt_re_password" type="password" class="normal_textbox" style="width:80%" maxlength="<?php echo CONST_RE_PASSWORD_MAXLENGTH; ?>" message="<?php echo CONST_RE_PASSWORD_MESSAGE;?>" optional="<?php echo $v_password_optional;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr><?php
	if (sizeof($arr_single_citizen)>0){?>
	<tr>
		<td class="normal_label"><?php echo CONST_PASSWORD_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_link">&nbsp;&nbsp;<a href="#" onclick="show_chanege_password_onclick('/isa-onegate/record/customer/index.php','DISPLAY_CHANGE_PASSWORD');"><?php echo CONST_CHANGE_PASSWORD_LINK;?></a></td>
	</tr><?php
	}?>
	<tr>
		<td colspan="10"><?
	$v_html_string = "";
	//Doc cac dong cua form	
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_xml_string_in_file);
	$table_struct_rax->record_delim = 'update_row';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	//Bang chua cac dong cua form
	$v_html_string = $v_html_string . "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td>";
	while ($table_struct_rec) { 
		$table_struct_row = $table_struct_rec->getRow();
		$v_have_line_before = $table_struct_row["have_line_before"];
		$v_tag_list = $table_struct_row["tag_list"];
		$v_row_id = $table_struct_row["row_id"];
		$arr_tag = explode(",", $v_tag_list);
		if ($v_have_line_before=="true"){
			$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
			$v_html_string = $v_html_string . "<td><hr width='100%' color='#66CCFF' size='1'></td>";
			$v_html_string = $v_html_string . "</tr></table>";
		}
		//Bang chua mot dong cua form
		$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
		$v_html_table = "";
		$v_html_tag = "";									
		for($i=0;$i < sizeof($arr_tag);$i++){
			$formfield_rax = new RAX(); 
			$formfield_rec = new RAX(); 
			$formfield_rax->open($v_xml_string_in_file);
			$formfield_rax->record_delim = $arr_tag[$i];
			$formfield_rax->parse();
			$formfield_rec = $formfield_rax->readRecord(); 
			$formfield_row = $formfield_rec->getRow(); 
			$v_label = $formfield_row["label"];
			$v_type = $formfield_row["type"];
			$v_dataformat = $formfield_row["data_format"];
			$v_width = $formfield_row["width"];
			$v_row = $formfield_row["row"];
			$v_max = $formfield_row["max"];
			$v_min = $formfield_row["min"];
			$v_maxlength = $formfield_row["maxlength"];
			$v_note = $formfield_row["note"];
			$v_tooltip = $formfield_row["tooltip"];
			$v_message = $formfield_row["message"];
			$v_optional = $formfield_row["optional"];
			$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
			$v_js_function_list = $formfield_row["js_function_list"];
			$v_js_action_list = $formfield_row["js_action_list"];
			$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
			$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
			if ($v_xml_str!=""){
				$column_rax = new RAX(); 
				$column_rec = new RAX();
				$column_rax->open($v_xml_str);
				$column_rax->record_delim = 'data_list';
				$column_rax->parse();
				$column_rec = $column_rax->readRecord(); 
				$column_row = $column_rec->getRow();
				$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
			}
			if ($v_type=="selectbox"){
				$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
				$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
				$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
			}
			if ($v_type=="checkboxmultiple"){
				$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
				$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
				$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
			}
			$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
			$v_html_tag = $v_html_tag . Generate_HTML_Input();		
		}
		$v_html_string = $v_html_string .  $v_html_table . "<tr id = '$v_row_id' style='display:block'>" . "<td class='normal_label'>" . $v_html_tag."</td>";
		$v_html_string = $v_html_string . "</tr></table>";
		$table_struct_rec = $table_struct_rax->readRecord();
	}
	$v_html_string = $v_html_string . "</td></tr>";
	$v_html_string = $v_html_string . "</table>";//Bat dau dong chua bang phe duyet ho so
	echo $v_html_string;
	//Ket thuc cua bang phia tren

	if (sizeof($arr_single_citizen)==0){?>
	<tr>
		<td class="normal_label" colspan="4"><?php echo CONST_SECURITY_LABEL;?></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QUESTION_SECURITY_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_label" colspan="3">
			<select class="normal_selectbox" name="sel_question" style="width:80%"  message = "<?php echo CONST_QUESTION_SECURITY_MESSAGE; ?>" onChange="document.forms(0).hdn_question.value = this.value">
            <option id="" value="">------&nbsp;&nbsp;<?php echo CONST_QUESTION_SECURITY_SELECTBOX_LABEL;?>&nbsp;&nbsp;------</option>
            <?php echo _generate_select_option($arr_all_question,'C_CODE','C_CODE','C_NAME', $v_question_id);?>
          </select>
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_ANSWER_SECURITY_LABEL;?><small class="small_starmark">*</small></td>
		<td class="normal_label"><input name="txt_answer" type="text" class="normal_textbox" style="width:80%" message="<?php echo CONST_ANSWER_SECURITY_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label" colspan="4"><?php echo CONST_RANDOM_NUMBER_LABEL;?><small class="small_starmark">*</small></td>
	</tr>
	<tr>
		<td class="normal_label">&nbsp;</td>
		<td class="normal_label"><input name="txt_random_number" type="text" class="normal_textbox" style="width:80%" message="<?php echo CONST_RANDOM_NUMBER_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label">&nbsp;</td>
		<td class="normal_label"><?php create_image($str_random,7,"random.jpg");?><img src='random.jpg'></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_COMMIT_LABEL;?></td>
		<td class="normal_label"><textarea name="txt_commit_content" class="normal_textarea" rows="5" optional = "true" style="width:100%"><?php echo CONST_COMMIT_CONTENT_LABEL.CONST_COMMIT_CONTENT1_LABEL.CONST_COMMIT_CONTENT2_LABEL?></textarea></td>
	</tr><?php
	}?>
	</td>
	</tr>
	<tr><td>&nbsp;</td></tr>
</table>
<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
	<tr height="5pt"><td>&nbsp;</td></tr>
	<tr align="center">
		<td>
			<input type="button" name="btn_save"  class="normal_button" value="<?php echo $v_register_button ;?>" onClick="btn_citizen_update('UPDATE_CITIZEN');" onKeyDown="change_focus(document.forms(0),this)">
			<input type="button" name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('<?php echo $_GO_BACK?>');" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
</table>
<!--//End//Form-->
</form>
<script language="JavaScript">
	set_focus(document.forms(0));
</script>